package twoD.IsoPfem.Plasticity.Perfect;

import inf.jlinalg.Array2DMatrix;
import inf.jlinalg.IMatrix;
import inf.jlinalg.IVector;

import java.util.ArrayList;

import oneD.fem.algorithm.ITensor;
import oneD.fem.algorithm.Tensor2;
import oneD.fem.algorithm.Tensor4;
import twoD.IsoPfem.CST;
import twoD.IsoPfem.IGeometry;
import twoD.IsoPfem.RealTable;
import twoD.IsoPfem.Plasticity.IPlasticElement;
import twoD.IsoPfem.Plasticity.IYieldCriterion;

public class PlasticCST extends CST implements IPlasticElement {

	private static final double TOL = 1e-6;

	private Tensor4 tangentOperator_;
	private Tensor2 sigma_;
	private ArrayList<PlasticState> state_;

	public PlasticCST(RealTable realTable, IGeometry T) {
		super(realTable, T);
		state_ = new ArrayList<PlasticState>();
		tangentOperator_ = new Tensor4(2);
		sigma_ = new Tensor2(2);
	}

	@Override
	public IVector computeSigma(double... xi) {
		return sigma_.getVectorForm();
	}

	@Override
	public IMatrix getCMatrix() {
		IMatrix C = new Array2DMatrix(3, 3);
		C.set(0, 0, tangentOperator_.get(0, 0, 0, 0));
		C.set(0, 1, tangentOperator_.get(0, 0, 1, 1));
		C.set(0, 2, tangentOperator_.get(0, 0, 0, 1));
		C.set(1, 0, tangentOperator_.get(1, 1, 0, 0));
		C.set(1, 1, tangentOperator_.get(1, 1, 1, 1));
		C.set(1, 2, tangentOperator_.get(1, 1, 0, 1));
		C.set(2, 0, tangentOperator_.get(0, 1, 0, 0));
		C.set(2, 1, tangentOperator_.get(0, 1, 1, 1));
		C.set(2, 2, tangentOperator_.get(0, 1, 0, 1));
		return C;

	}

	public int getCurrentStep() {
		return state_.size() - 1;
	}

	public void updateInternalState(IYieldCriterion yieldCriterion) {
		
	}


	private double computeDeltaLambda(ITensor xi, IYieldCriterion yieldCriterion) {
		double deltaLambda = 0;

		return deltaLambda;
	}
}
